package com.itheima.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.itheima.domain.db.Admin;
import com.itheima.manager.UserManager;
import com.itheima.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.jedis.JedisUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
public class UserControler {

    @Autowired
    private UserManager userManager;

    // 发送短信
    @RequestMapping("/user/sendSMS")
    public String sendSMS(String telephone){

        userManager.sendSms(telephone);

        // 成功返回
        return "OK";
    }

    // 登录
    @RequestMapping("/user/login")
    public String login(String telephone, String code){
        return userManager.login(telephone,code);
    }

    // 根据当前登录手机号查询管理员信息(数据回显)
    @RequestMapping("/adminInfoByTelephone")
    public Admin adminInfoByTelephone(@RequestParam(value = "telephone",defaultValue = "15725552051") String telephone){
        Admin admin = userManager.adminInfoByTelephone(telephone);
        System.out.println(admin);
        return admin;
    }



    /*@RequestMapping(name="判断用户是否登录（token）",value = "/isLogin")
    public void isLogin(@RequestHeader("Authorization") String token){
        try {
            Map map = JwtUtil.parseToken(token);
            User user = BeanUtil.mapToBean(map, User.class, true);
            //用当前用户操作
            System.out.println("当前用户登录了 可以操作了");
        }catch (Exception e){
            System.out.println("没登录~");
        }
    }*/

}
